//Snake class
#include <ctime>

using namespace std;

class Snake{
	public:
		enum 	Direct{Up, Down, Left, Right};	
		int 	steps, eated;
		int 	quads;
		int     fitness;
		int 	level;
		int 	minExp, maxExp, curExp;
		int 	moveSpeed;
		int 	resSpeed;

		struct Quad{
			int posix;
			int posiy;
			int way;
		};

		vector <Quad> sQuad;
		Quad snake;
		vector <Quad>::iterator iterQuad;

		Snake();
		~Snake();
		void 	setFitness();
		void 	incSteps();
		void 	incEated();
		void 	setPos(int x, int y);
		void 	incQuads();
		void 	addQuad();
		void 	addExp(int amount);
		void 	levelGain();
		void 	restoreSpeed();
};

Snake::Snake(){

	srand(time(NULL));

	steps   = 0;
	eated   = 0;
	quads   = 1;
	fitness = 0;
	level   = 1;

	minExp  = 0;
	maxExp  = 10;
	curExp  = 0;
	moveSpeed = 15;
	resSpeed = 15;

	iterQuad = sQuad.begin();
	snake.posix = rand() % GetSystemMetrics(SM_CXSCREEN);
	snake.posiy = rand() % GetSystemMetrics(SM_CYSCREEN);
	snake.way   = Up;
	sQuad.push_back(snake);
}

Snake::~Snake(){}

void Snake::setFitness(){
	fitness = eated / (double)steps * 100;
}

void Snake::incSteps(){
	steps += 1;
}

void Snake::incEated(){
	eated += 1;
}

void Snake::setPos(int x, int y){
	snake.posix += x;
	snake.posiy += y;
}

void Snake::incQuads(){
	quads += 1;
}

void Snake::addQuad(){

	snake.way = sQuad.back().way;

	switch(sQuad[sQuad.size() - 1].way){
		case Up:
			snake.posiy = sQuad.back().posiy + 20;
			break;
		case Down:
			snake.posiy = sQuad.back().posiy - 20;
			break;
		case Left:
			snake.posix = sQuad.back().posix + 20;
			break;
		case Right:
			snake.posix = sQuad.back().posix - 20;
			break;
	}
	sQuad.push_back(snake);
}

void Snake::addExp(int amount){
	curExp += amount;
	if(curExp >= maxExp){
		levelGain();
	}
}

void Snake::levelGain(){
	level ++;
	curExp = 0;
	minExp = 0;
	maxExp = maxExp * 1.2;
	resSpeed = resSpeed - 3;
	if (resSpeed <=  3)
		resSpeed = 3;
}

void Snake::restoreSpeed(){
	moveSpeed = resSpeed;
}